﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraSplashScreen;
using ISumen;
using Sumen.Business;
using Sumen.Business.Model;
using Sumen.Business.Model.Presenter.Category;
using Sumen.Business.Model.Presenter.Inventory;
using Sumen.Business.Model.Presenter.Sys;
using Sumen_Stock.LookAndFeel.Sumen_System;

namespace Sumen_Stock.LookAndFeel.Inventory
{
    public partial class Frm_Inventory : DevExpress.XtraEditors.XtraForm
    {
        private FromCode _fromCode = FromCode.FrmInventory;
        #region Presenter

        private InventoryPresenter _inventoryPresenter;
        private StockPresenter _stockPresenter;

        #endregion

        #region From

        public Frm_Inventory()
        {
            InitializeComponent();
            _inventoryPresenter = new InventoryPresenter();
            _stockPresenter = new StockPresenter();
            //if (ClsPublic.Writelog == "1")
            //{
            //    SysLogPresenter log = new SysLogPresenter();
            //    log.Add(_fromCode, EnumFormStatus.Modify, "", "");
            //}
        }

        private void Frm_Inventory_Load(object sender, EventArgs e)
        {
            LoadForm();
        }

        public override void Refresh()
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            base.Refresh();
            LoadForm();
            SplashScreenManager.CloseForm();
        }

        #endregion

        #region Control event

        private void btnView_Click(object sender, EventArgs e)
        {
            LoadInventory(lookUpStock.EditValue + string.Empty);
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {

        }

        private void btnExcel_Click(object sender, EventArgs e)
        {
            //gridView1.ExportToXlsx("e:/123.xlsx");
        }

        #endregion

        #region Gridview event


        #endregion



        #region Method

        void LoadForm()
        {
            LoadInventory(lookUpStock.EditValue + string.Empty);
            LoadStock();
        }

        void LoadInventory(string pStockID)
        {
            var query = _inventoryPresenter.GetByKey(pStockID);
            gridControl1.DataSource = query.First();
            gridView1.ExpandAllGroups();
            gridView1.BestFitColumns();
        }

        void LoadStock()
        {
            lookUpStock.Properties.DataSource = _stockPresenter.GetAll();
        }

        #endregion

        private void chkShowPicture_CheckedChanged(object sender, EventArgs e)
        {
            if (chkShowPicture.Checked)
            {
                colPicture.VisibleIndex = 0;
                gridView1.RowHeight = 50;
            }
            else
            {
                colPicture.VisibleIndex = -1;
                gridView1.RowHeight = -1;
            }
        }







    }
}